package org.jeecg.modules.demo.util;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;

public class Utils {
    public void  test() {
        // 整数2000
        short  number = 1000;

        List<Short> list = new ArrayList();
        list.add((short) 2000);
        list.add((short) 0);
        list.add((short) 1000);
        for (Short o : list) {
            ByteBuffer buffer = ByteBuffer.allocate(2); //通过传过来的参数 先知道是多少字节然后指定转换类型在转换
            buffer.order(ByteOrder.LITTLE_ENDIAN); // 设置小端序
            buffer.putShort(o);
            // 获取字节数组
            byte[] bytes = buffer.array();
            // 输出字节数组的十六进制表示
            for (byte b : bytes) {


                String format = String.format("%02X ", b);
                System.out.print(format);
            }
        }
    }
}
